<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html style="background:linear-gradient(to bottom,#fff, #ddd,#fff)">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>

    <style type="text/css">
        * {
            text-align: center;
        }

        span {
            color: red;
        }
    </style>
</head>
<body>
<div style="width:100%;height:100%;display:none;background-color:white;position: fixed;top:0px;left:0px;" onclick="xiaoshi(this)" id="derror">
    <img src="${pageContext.request.contextPath}/img/false.gif" width="40%" style="position: absolute;top:20px;left:300px;" id="cuo">
</div>

<img src="${pageContext.request.contextPath}/img/fei.gif" width="100%" style="display:none;position: fixed;top:0px;left:0px;" id="waitimg">
<h2>开始答题</h2>
<hr/>

<form id="f1" method="post">

    <input type="hidden" name="id" value="${ti.id}">
    <input type="hidden" name="method" value="${ti.method}">
    <%--<input type="hidden" name="answer" value="${ti.answer}">--%>

    <p style="width:60%;margin:auto;text-align: left;">难度:
        <c:forEach begin="1" end="${ti.degree}">
        <img  src="${pageContext.request.contextPath}/img/star.jpg"/></c:forEach>
    </p>

    <p style="width:60%;margin:auto;text-align: left;">
        <textarea id="ta" style="text-align: left;" rows="20" cols="120" name="content"
                  required>/*${ti.content}&#10;*/</textarea>
    </p><br/>
    <input type="button" onclick="tijiao()" value="提交"/>
</form>
</body>

<script src="${pageContext.request.contextPath}/js/jquery-1.12.4.min.js"></script>
<script>

    function xiaoshi(obj) {
        $(obj).hide();
    }
    function tijiao() {
        'use strict';
        var url;
        if(!"${ti.url}"){
            url = "${pageContext.request.contextPath}/sql/panduan";
        }else{
            url = "${pageContext.request.contextPath}/dati${ti.url}";
        }
        $.ajax({
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: url,
            data: $('#f1').serialize(),
            success: function (result) {
                if (result.code == 1) {
                    location.replace("${pageContext.request.contextPath}/yanhua.jsp?pagenum=${param.pagenum}")
                } else if(result.code == 101){
                    location.replace("${pageContext.request.contextPath}/login.jsp?error="+encodeURI('登录过期,请重新登录'))
                }else {
                    $("#derror").show();
                }
            },

            error:function () {
                $("#derror").show();
            },
            beforeSend: function(){
                $("#waitimg").show();
            },
            complete: function(){
                $("#waitimg").hide();
            }
        });
    }
</script>
</html>